package com.chaopei.day01;

import java.util.Scanner;

/*
 *@Author Corday 天涯
 *@Date 2022/3/3 11:21
 */
public class MyProgram {
    public static void main(String[] args) {
//        selectSentence();
//        recycleSentence();
//        go();
//        strongFor();
        playAuthentication();
    }

    //    程序流程控制语句,选择语句与循环语句
    public static void selectSentence() {
//1.if双分支
        int face = 90;
//    使用键盘输入
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入:");
        face = sc.nextInt();
        if (face > 90) {
            System.out.println("颜值:" + face + " 帅");
        } else {
            System.out.println("加油!");
        }
//2.多分支
        if (face > 90 && face <= 100) {
            System.out.println("very nice!");
        } else if (face > 70 && face <= 90) {
            System.out.println("nice");
        } else if (face >= 60 && face <= 70) {
            System.out.println("good!");
        } else {
            System.out.println("just so so!");
        }
        System.out.println("----------------");
        double money = 8888;
        System.out.println("请输入财富:");
        money = sc.nextDouble();
        if (money > 900000) {
            System.out.println("very good!");
        } else if (money > 400000 && money <= 900000) {
            System.out.println("good!");
        } else {
            System.out.println("ok");
        }
//  关闭键盘输入流
        sc.close();
        //switch语句,用于序列数据的分支,比如:一个星期,一个季度,十二月
        //进行汉字转换
        int week = 3;
        //变量或表达式,结果是:String,int,char,byte
        switch (week) {
            case 0:
                System.out.println("星期天");
                break;
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            default:
                System.out.println("有误!");
                break;
        }
    }

    //2.循环语句
    public static void recycleSentence() {
//        2.1标准for,增强型for
        //找数
        for (int i = 100; i <= 200; i++) {
            if (i % 13 == 0 && i % 7 == 0) {
                System.out.println("此数为:" + i);
            }
        }
        //九九乘法口诀表
        for (int i = 1; i <= 9; i++) {//行号
            for (int j = 1; j <= i; j++) {
                System.out.print(i + "*" + j + "=" + (i * j) + " ");
            }
            System.out.println();
        }
        //分别运用for与while循环找出300-500之间的素数(质数)
        for (int i = 3; i < 20; i++) {
            //赋初值为false,开始暂定是素数
            boolean flag = false;
            for (int j = 2; j < i / 2 + 1; j++) {
                if (i % j == 0) {
                    flag = true;
                    break;
                }
            }//for1
            if (!flag) {
                System.out.println("素数为：" + i);
            }
        }//for2
        System.out.println("---------------");
        int i = 3;
        while (i < 20) {
            i++;
            boolean flag = true;
            int j = 2;
            while (j <= i / 2 + 1) {
                j++;
                if(i%j==0){
                    flag = false;
                    break;
                }
            }//while1
           if(flag){
               System.out.println(i);
           }
        }//while2
        int x=20;
        do{
            System.out.println("执行一次");
        }while (x>30);
        //注意：一定要有结束循环的条件
    }//recycle
// 更多的练习
   public static  void go(){
    //1．输出26个英文字符,其中G输出为小写，其它大写，并输出对应的ASCII值
       char ch ='A';
       short i=0;
       while (i<=25){
           if((char)(ch+i)=='G'){
               System.out.print("g"+":"+(short)'g'+" ");
           }else{
               System.out.print((char)(ch+i)+":"+(ch+i)+" ");
           }
           i++;
       }
    }//go
// 3.增强型for,遍历数组，集合
    public  static  void strongFor(){
        //数字0的ASCII为48
        char[] chs ={'c','a','u',48,90,98,'z'};
        for(char c: chs){
            System.out.print(c+" ");
        }
        System.out.println();
        for(int i=0;i<chs.length;i++){
            System.out.print(chs[i]+" ");
        }
    }
//    4.基本算法
    public  static  void playAuthentication(){
        //一个四位数,恰好等于去掉它的首位数字之后
        // 所剩的三位数的3倍,求这个数并打印输出
        //2134
        for(int i=1000;i<=9999;i++){
            int temp = (i%1000)*3;
            if(i==temp){
                System.out.println("此数为:"+i);
            }
        }//for
//        打印输出30x5的空心矩形,用*号表示
        for(int i=1;i<=5;i++){//行
            for(int j=1;j<=30;j++){//列
                if(i>1&&i<5){
                    if(j==1||j==30){
                        System.out.print("*");
                    }else{
                        System.out.print(" ");
                    }
                }else{
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }//playa

}
